package org.example.book.normal.state.order;

import org.example.book.util.RedisCommonProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DeprecatedReceiveOrder extends DeprecatedOrderState{

    @Autowired
    private RedisCommonProcessor commonProcessor;
    @Override
    protected DeprecateOrder receiveOrder(String orderId, DeprecatedOrderContext context) {
        DeprecateOrder order = (DeprecateOrder) commonProcessor.get(orderId);
        if (!order.getState().equals(ORDER_WAIT_SEND)) {
            throw new UnsupportedOperationException("order state must be WAIT_SEND");
        }
        order.setState(ORDER_FINISH);
        super.notifyObserver(orderId, ORDER_FINISH);
        return order;
    }
}
